package org.kineticsproject.application.util;

import data.Person;
import data.DataFactory;

import java.io.File;
import java.io.IOException;
import java.sql.Date;
import org.eclipse.emf.ecore.resource.impl.*;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.emf.common.util.*;



public class PopulatePerson {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException{
		
		Person person = DataFactory.eINSTANCE.createPerson();
		person.setHeight((float) 70.2);
		person.setName("Casey Kelso");
		person.setWeight((float)72.8);
		Date d = new Date(0);
		person.setDateOfBirth(d);
			
		//Create new ResourceSet & Resource
		ResourceSet resourceSet = new ResourceSetImpl();
		
		// Register XML resource factory
		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", 
		new XMIResourceFactoryImpl());

		Resource resource = resourceSet.createResource(URI.createFileURI(new File("myPerson.xmi").getAbsolutePath()));

		// add the root object to the resource
		resource.getContents().add(person);
		// serialize resource – you can specify also serialization
		// options which defined on org.eclipse.emf.ecore.xmi.XMIResource
		resource.save(null);
		
	}
		
		
}

